﻿using System.Reactive.Linq;
using WkyApiSharp.Events.Account;
using WkyApiSharp.Service;

namespace LocalNas.Application.Module.Wankeyun;
public class WankeyunApi : ISingleton
{
    private WkyApi wkyApi;
    public WankeyunApi()
    {
        var user = "15527882018";// File.ReadAllText("user.txt");
        var password = "solosoul627@";// File.ReadAllText("password.txt");
        wkyApi = new WkyApi(user, password, WkyLoginDeviceType.PC);
        wkyApi.EventReceived
            .OfType<LoginResultEvent>()
            .Subscribe(r =>
            {
                Console.WriteLine("登录成功");
            });

        wkyApi.EventReceived
            .OfType<UpdateDeviceResultEvent>()
            .Subscribe(r =>
            {
                Console.WriteLine("设备更新完毕");
            });

        wkyApi.EventReceived
            .OfType<DownloadSuccessEvent>()
            .Subscribe(r =>
            {
                Console.WriteLine("下载完成");
            });

        wkyApi.EventReceived
            .OfType<UpdateTaskListEvent>()
            .Subscribe(r =>
            {
                Console.WriteLine("任务列表更新");
                var device = wkyApi.GetAllDevice();
            });

        var result = wkyApi.StartLogin().Result;
        if (result)
        {
            //DeviceTest(wkyApi);



        }
    }

    public void GetDevice()
    {
        var device = wkyApi.GetAllDevice();

    }
}
